package com.ayf.payment.game.api.controller.platform;

import com.ayf.payment.game.api.channel.alipay.internal.util.StringUtils;
import com.ayf.payment.game.api.dto.ayb.SignPayProductDTO;
import com.ayf.payment.game.api.dto.ayb.SignPayProductDTO2;
import com.ayf.payment.game.api.dto.criteria.SignPayProductCriteria;
import com.ayf.payment.game.api.dto.sign.*;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.service.SignPayProductService;
import com.ayf.payment.game.api.service.payment.ayb.MerchantTwoService;
import com.ayf.payment.game.api.service.sign.MerchantTwoSignService;
import com.ayf.payment.game.api.type.CommonConstants;
import com.ayf.payment.game.api.utils.CommonResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 二级商户管理
 */
@RequestMapping("/t/ayb")
@RestController
public class MerchantTwoManagerController {

    @Autowired
    private MerchantTwoService merchantTwoService;
    @Autowired
    private SignPayProductService signPayProductService;
    @Autowired
    private MerchantTwoSignService merchantTwoSignService;

    /**
     * 查询二级商户列表
     *

     * @param selectCriteria
     * @return
     */
    @PostMapping("/selectPageSignPayProduct")
    public CommonResult<PageInfo> selectPageSignPayProduct(@RequestBody SignPayProductCriteria selectCriteria) {
        PageHelper.startPage(selectCriteria.getPageNum(), selectCriteria.getPageSize());
        List<SignPayProductDTO2> signPayProductDTOS = signPayProductService.selectPageSignPayProduct(selectCriteria);
        PageInfo pageInfo = new PageInfo(signPayProductDTOS);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, CommonConstants.OPERATION_SUCCESS, pageInfo);
    }

    /**
     * 查询二级商户详情
     *
     * @param
     * @return
     */
    @PostMapping("/getSignPayProductDetail")
    public CommonResult<SignPayProductDTO> getSignPayProductDetail(@RequestBody SignPayProductCriteria criteria) {
        SignPayProductDTO signPayProductDTO = signPayProductService.getSignPayProductDTOById(criteria.getId());
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, CommonConstants.OPERATION_SUCCESS, signPayProductDTO);
    }

    /**
     * 申请
     * @param reqDTO
     * @return
     */
    @RequestMapping("/merchantTwo_apply")
    public CommonResult<?> getMerchantApplyData(@RequestBody MerchantTwoApplyReqDTO reqDTO) {
        if(reqDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(reqDTO.getMerchantId()==null && reqDTO.getMerchantId()<=0){
            throw new ParameterException("商户ID不能为空");
        }
        if(StringUtils.isEmpty(reqDTO.getChannelCode())){
            throw new ParameterException("通道类型不能为空");
        }
        MerchantTwoApplyResDTO merchantTwoApplyResDTO= merchantTwoSignService.merchantTwoApply(reqDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, CommonConstants.OPERATION_SUCCESS, merchantTwoApplyResDTO);
    }
    /**
     * 查询状态
     * @param merchantTwoSelectReqDTO
     * @return
     */
    @RequestMapping("/merchantTwo_qurey")
    public CommonResult merchantQurey(@RequestBody MerchantTwoSelectReqDTO merchantTwoSelectReqDTO) {
        if(merchantTwoSelectReqDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(merchantTwoSelectReqDTO.getMerchantId()==null && merchantTwoSelectReqDTO.getMerchantId()<=0){
            throw new ParameterException("商户ID不能为空");
        }
        if(StringUtils.isEmpty(merchantTwoSelectReqDTO.getChannelCode())){
            throw new ParameterException("通道类型不能为空");
        }
        MerchantTwoSelectResDTO twoSelectResDTO= merchantTwoSignService.merchantTwoSelect(merchantTwoSelectReqDTO);
        return new CommonResult(CommonConstants.RETURN_SUCCESS,"查询成功",twoSelectResDTO);
    }
    /**
     * 更新
     * @param merchantTwoUpdateReqDTO
     * @return
     */
    @RequestMapping("/merchantTwo_update")
    public CommonResult merchantTwoUpdate(@RequestBody MerchantTwoUpdateReqDTO merchantTwoUpdateReqDTO) {
        if(merchantTwoUpdateReqDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(merchantTwoUpdateReqDTO.getMerchantId()==null && merchantTwoUpdateReqDTO.getMerchantId()<=0){
            throw new ParameterException("商户ID不能为空");
        }
        if(StringUtils.isEmpty(merchantTwoUpdateReqDTO.getChannelCode())){
            throw new ParameterException("通道类型不能为空");
        }
        MerchantTwoUpdateResDTO merchantTwoUpdateResDTO= merchantTwoSignService.merchantTwoUpdate(merchantTwoUpdateReqDTO);
        return new CommonResult(CommonConstants.RETURN_SUCCESS,CommonConstants.OPERATION_SUCCESS,merchantTwoUpdateResDTO);
    }
    /**
     * 解约
     * @param merchantTwoUpdateSuperReqDTO
     * @return
     */
    @RequestMapping("/merchantTwo_updata_super")
    public CommonResult merchantTwoUpdataSuper(@RequestBody MerchantTwoUpdateSuperReqDTO merchantTwoUpdateSuperReqDTO) {
        if(merchantTwoUpdateSuperReqDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(merchantTwoUpdateSuperReqDTO.getMerchantId()==null && merchantTwoUpdateSuperReqDTO.getMerchantId()<=0){
            throw new ParameterException("商户ID不能为空");
        }
        if(StringUtils.isEmpty(merchantTwoUpdateSuperReqDTO.getChannelCode())){
            throw new ParameterException("通道类型不能为空");
        }
        MerchantTwoUpdateSuperResDTO updateSuperResDTO= merchantTwoSignService.merchantTwoUpdateSuper(merchantTwoUpdateSuperReqDTO);
        return new CommonResult(CommonConstants.RETURN_SUCCESS,"解约成功",updateSuperResDTO);
    }

}
